From: <mar...@us...> - 2008-05-08 07:44:12
|
Revision: 172 http://gridsim.svn.sourceforge.net/gridsim/?rev=172&view=rev Author: marcos_dias Date: 2008-05-08 00:44:14 -0700 (Thu, 08 May 2008) Log Message: ----------- Small improvements in the allocation policies to allow the user to extend the advance reservation methods and implement his own logging features. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.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/TAllocPolicy.java Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-05-08 07:44:14 UTC (rev 172) @@ -294,29 +294,40 @@ /** * Handles an advance reservation request.<br> * @param message the advance reservation message received + * @return <tt>true</tt> if the reservation has been accepted; + * <tt>false</tt> otherwise. * @pre message != null */ - public void handleCreateReservation(ARMessage message) { + public boolean handleCreateReservation(ARMessage message) { double currentTime = GridSim.clock(); + boolean success; // gets the reservation object and extract some // information from it Reservation reservation = message.getReservation(); - double startTime = reservation.getStartTime(); - int duration = reservation.getDurationTime(); - int reqPE = reservation.getNumPE(); - if(startTime == 0 || startTime < currentTime) - startTime = currentTime; - // creates a Server Side Reservation (i.e. SSReservation) SSReservation sRes = new SSReservation(reservation); - sRes.setPartitionID(profile_.getCorrespondingPartitionID(sRes)); - double expTime = Double.NaN; - + // creates a response message to be sent to the requester ARMessage response = message.createResponse(); + // validate the reservation, check num of PEs required, partition, etc. + success = validateReservation(sRes); + + if(!success) { + reservation.setStatus(Reservation.STATUS_FAILED); + response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); + sendARMessage(response); + return false; + } + + double startTime = reservation.getStartTime(); + if(startTime == 0 || startTime < currentTime) + startTime = currentTime; + + double expTime = Double.NaN; + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // informs the listeners that a reservation request has arrived @@ -324,24 +335,7 @@ AllocationAction.ITEM_ARRIVED, true, sRes); //---------------------------------------------------------- - - if (reqPE > super.totalPE_) { - String userName = GridSim.getEntityName( message.getSourceID() ); - System.out.println(super.get_name() + ".handleCreateReservation():" + - " Reservation #" + reservation.getID() + " from " + - userName + " user requires " + reservation.getNumPE() + - " PEs from " + startTime + " to " + (startTime + duration)); - System.out.println("--> The resource has only " + - super.totalPE_ + " PEs available."); - - reservation.setStatus(Reservation.STATUS_FAILED); - response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); - sendARMessage(response); - return; - } - boolean success = true; - // if start time = current time, then it is an immediate reservation if(startTime == currentTime) { success = handleImmediateReservation(sRes); @@ -355,9 +349,9 @@ if(!success) { String userName = GridSim.getEntityName( message.getSourceID() ); System.out.println(super.get_name() + ".handleCreateReservation():" + - " Reservation #" + reservation.getID() + " from " + - userName + " user requires " + reservation.getNumPE() + - " PEs from " + startTime + " to " + (startTime + duration)); + " Reservation #" + sRes.getID() + " from " + + userName + " user requires " + sRes.getNumPE() + + " PEs from " + startTime + " to " + sRes.getActualFinishTime()); System.out.println("--> The resource could not handle the reservation."); // Gets availability information and provides it as options @@ -370,7 +364,7 @@ reservation.setReservationOptions(availability); response.setErrorCode(ARMessage.EC_OPERATION_FAILURE_BUT_OPTIONS); sendARMessage(response); - return; + return false; } // if the expiration time is greater than the start time of the @@ -408,13 +402,18 @@ // Informs the listeners about the reservation that has been created GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sRes); + + //---------------------------------------------------------- + return true; } /** * Handles a commit reservation request. * @param message the advance reservation message received + * @return <tt>true</tt> if the reservation has been committed; + * <tt>false</tt> otherwise. */ - public void handleCommitReservation(ARMessage message) { + public boolean handleCommitReservation(ARMessage message) { // gets the reservation id of the message int reservationId = message.getReservationID(); @@ -462,7 +461,7 @@ if(!success) { response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); sendARMessage(response); - return; + return false; } // sets the reservation to committed if it has not been set before @@ -481,28 +480,32 @@ GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_STATUS_CHANGED, true, sRes); - //---------------------------------------------------------- + return true; } /** * Handles a modify reservation request<br> * (NOTE: <b>NOT SUPPORTED YET</b>). * @param message the advance reservation message received. + * @return <tt>false</tt>. */ - public void handleModifyReservation(ARMessage message) { + public boolean handleModifyReservation(ARMessage message) { System.out.println(super.get_name() + ".handleModifyReservation(): not supported at the moment."); + return false; } /** * Handles a cancel reservation request<br> * (NOTE: <b>NOT SUPPORTED YET</b>). * @param message the advance reservation message received. + * @return <tt>false</tt>. */ - public void handleCancelReservation(ARMessage message) { + public boolean handleCancelReservation(ARMessage message) { System.out.println(super.get_name() + ".handleCancelReservation(): not supported at the moment."); + return false; } /** @@ -589,6 +592,41 @@ // --------------------- PROTECTED METHODS ----------------------- /** + * Checks whether the reservation can be handled by the resource. That is, + * verifies if it does not require more resources than what the resource + * can provide and if the corresponding partition can handle the reservation. + * @param res the server side reservation to be examined + * @return <tt>true</tt> if it can be handled; <tt>false</tt> otherwise. + */ + protected boolean validateReservation(SSReservation res) { + int reqPE = res.getNumPE(); + + if (reqPE > super.totalPE_) { + String userName = GridSim.getEntityName( res.getSenderID() ); + System.out.println(super.get_name() + ".validateReservation():" + + " Reservation #" + res.getID() + " from " + + userName + " user requires " + reqPE + + " PEs from " + res.getStartTime() + " to " + res.getActualFinishTime()); + System.out.println("--> The resource has only " + + super.totalPE_ + " PEs available."); + return false; + } + + // gets the id of the partition that can handle the reservation + int partitionId = profile_.getCorrespondingPartitionID(res); + if(partitionId == UNKNOWN) { + String userName = GridSim.getEntityName( res.getSenderID() ); + System.out.println(super.get_name() + ".validateReservation():" + + " Reservation #" + res.getID() + " from " + + userName + " cannot be served because no partition can do so."); + return false; + } + + res.setPartitionID(partitionId); + return true; + } + + /** * This method is called to update the schedule. It removes completed * gridlets and return them to the users and verifies whether there are * gridlets in the waiting list that should start execution. It also Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java 2008-05-08 07:44:14 UTC (rev 172) @@ -302,29 +302,40 @@ /** * Handles an advance reservation request.<br> * @param message the advance reservation message received + * @return <tt>true</tt> if the reservation has been accepted; + * <tt>false</tt> otherwise. * @pre message != null */ - public void handleCreateReservation(ARMessage message) { + public boolean handleCreateReservation(ARMessage message) { double currentTime = GridSim.clock(); + boolean success; // gets the reservation object and extract some // information from it Reservation reservation = message.getReservation(); - double startTime = reservation.getStartTime(); - int duration = reservation.getDurationTime(); - int reqPE = reservation.getNumPE(); - if(startTime == 0 || startTime < currentTime) - startTime = currentTime; - // creates a Server Side Reservation (i.e. SSReservation) SSReservation sRes = new SSReservation(reservation); - sRes.setPartitionID(profile_.getCorrespondingPartitionID(sRes)); - double expTime = Double.NaN; - + // creates a response message to be sent to the requester ARMessage response = message.createResponse(); + // validate the reservation, check num of PEs required, partition, etc. + success = validateReservation(sRes); + + if(!success) { + reservation.setStatus(Reservation.STATUS_FAILED); + response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); + sendARMessage(response); + return false; + } + + double startTime = reservation.getStartTime(); + if(startTime == 0 || startTime < currentTime) + startTime = currentTime; + + double expTime = Double.NaN; + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // informs the listeners that a reservation request has arrived @@ -332,24 +343,7 @@ AllocationAction.ITEM_ARRIVED, true, sRes); //---------------------------------------------------------- - - if (reqPE > super.totalPE_) { - String userName = GridSim.getEntityName( message.getSourceID() ); - System.out.println(super.get_name() + ".handleCreateReservation():" + - " Reservation #" + reservation.getID() + " from " + - userName + " user requires " + reservation.getNumPE() + - " PEs from " + startTime + " to " + (startTime + duration)); - System.out.println("--> The resource has only " + - super.totalPE_ + " PEs available."); - - reservation.setStatus(Reservation.STATUS_FAILED); - response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); - sendARMessage(response); - return; - } - boolean success = false; - // if start time = current time, then it is an immediate reservation if(startTime == currentTime) { success = handleImmediateReservation(sRes); @@ -363,9 +357,9 @@ if(!success) { String userName = GridSim.getEntityName( message.getSourceID() ); System.out.println(super.get_name() + ".handleCreateReservation():" + - " Reservation #" + reservation.getID() + " from " + - userName + " user requires " + reservation.getNumPE() + - " PEs from " + startTime + " to " + (startTime + duration)); + " Reservation #" + sRes.getID() + " from " + + userName + " user requires " + sRes.getNumPE() + + " PEs from " + startTime + " to " + sRes.getActualFinishTime()); System.out.println("--> The resource could not handle the reservation."); // Gets availability information and provides it as options @@ -378,7 +372,7 @@ reservation.setReservationOptions(availability); response.setErrorCode(ARMessage.EC_OPERATION_FAILURE_BUT_OPTIONS); sendARMessage(response); - return; + return false; } // if the expiration time is greater than the start time of the @@ -416,13 +410,18 @@ // Informs the listeners about the reservation that has been created GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sRes); + + //---------------------------------------------------------- + return true; } /** * Handles a commit reservation request. * @param message the advance reservation message received + * @return <tt>true</tt> if the reservation has been accepted; + * <tt>false</tt> otherwise. */ - public void handleCommitReservation(ARMessage message) { + public boolean handleCommitReservation(ARMessage message) { // gets the reservation id of the message int reservationId = message.getReservationID(); @@ -470,7 +469,7 @@ if(!success) { response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); sendARMessage(response); - return; + return false; } // sets the reservation to committed if it has not been set before @@ -491,26 +490,31 @@ AllocationAction.ITEM_STATUS_CHANGED, true, sRes); //---------------------------------------------------------- + return true; } /** * Handles a modify reservation request<br> * (NOTE: <b>NOT SUPPORTED YET</b>). * @param message the advance reservation message received. + * @return <tt>false</tt>. */ - public void handleModifyReservation(ARMessage message) { + public boolean handleModifyReservation(ARMessage message) { System.out.println(super.get_name() + ".handleModifyReservation(): not supported at the moment."); + return false; } /** * Handles a cancel reservation request<br> * (NOTE: <b>NOT SUPPORTED YET</b>). * @param message the advance reservation message received. + * @return <tt>false</tt>. */ - public void handleCancelReservation(ARMessage message) { + public boolean handleCancelReservation(ARMessage message) { System.out.println(super.get_name() + ".handleCancelReservation(): not supported at the moment."); + return false; } /** @@ -597,6 +601,41 @@ // --------------------- PROTECTED METHODS ----------------------- /** + * Checks whether the reservation can be handled by the resource. That is, + * verifies if it does not require more resources than what the resource + * can provide and if the corresponding partition can handle the reservation. + * @param res the server side reservation to be examined + * @return <tt>true</tt> if it can be handled; <tt>false</tt> otherwise. + */ + protected boolean validateReservation(SSReservation res) { + int reqPE = res.getNumPE(); + + if (reqPE > super.totalPE_) { + String userName = GridSim.getEntityName( res.getSenderID() ); + System.out.println(super.get_name() + ".validateReservation():" + + " Reservation #" + res.getID() + " from " + + userName + " user requires " + reqPE + + " PEs from " + res.getStartTime() + " to " + res.getActualFinishTime()); + System.out.println("--> The resource has only " + + super.totalPE_ + " PEs available."); + return false; + } + + // gets the id of the partition that can handle the reservation + int partitionId = profile_.getCorrespondingPartitionID(res); + if(partitionId == UNKNOWN) { + String userName = GridSim.getEntityName( res.getSenderID() ); + System.out.println(super.get_name() + ".validateReservation():" + + " Reservation #" + res.getID() + " from " + + userName + " cannot be served because no partition can do so."); + return false; + } + + res.setPartitionID(partitionId); + return true; + } + + /** * This method is called to update the schedule. It removes completed * gridlets and return them to the users and verifies whether there are * gridlets in the waiting list that should start execution. It also Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-05-08 07:44:14 UTC (rev 172) @@ -195,9 +195,11 @@ /** * Handles an advance reservation request.<br> * @param message the advance reservation message received + * @return <tt>true</tt> if the reservation was accepted; + * <tt>false</tt> otherwise. * @pre message != null */ - public void handleCreateReservation(ARMessage message) { + public boolean handleCreateReservation(ARMessage message) { double currentTime = GridSim.clock(); // gets the reservation object and extract some @@ -233,7 +235,7 @@ reservation.setStatus(Reservation.STATUS_FAILED); response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); sendARMessage(response); - return; + return false; } boolean success = true; @@ -380,16 +382,21 @@ reservation.setReservationOptions(availability); response.setErrorCode(ARMessage.EC_OPERATION_FAILURE_BUT_OPTIONS); sendARMessage(response); + return false; } + + return true; } /** * This method handles a cancel reservation request. * @param message the advance reservation message received requesting * the cancellation + * @return <tt>true</tt> if the reservation was cancelled; + * <tt>false</tt> otherwise. * @pre message != null */ - public void handleCancelReservation(ARMessage message) { + public boolean handleCancelReservation(ARMessage message) { double currentTime = GridSim.clock(); // gets the reservation id of the message @@ -426,7 +433,7 @@ if(!success) { response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); sendARMessage(response); - return; + return false; } boolean inProgress = sRes.getStatus() == Reservation.STATUS_IN_PROGRESS; @@ -461,13 +468,16 @@ // send the response message back to the requester sendARMessage(response); + return true; } /** * Handles a commit reservation request. * @param message the advance reservation message received + * @return <tt>true</tt> if the reservation was committed; + * <tt>false</tt> otherwise. */ - public void handleCommitReservation(ARMessage message) { + public boolean handleCommitReservation(ARMessage message) { double currentTime = GridSim.clock(); @@ -517,7 +527,7 @@ if(!success) { response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); sendARMessage(response); - return; + return false; } // sets the reservation to committed if it has not been set before @@ -538,16 +548,19 @@ AllocationAction.ITEM_STATUS_CHANGED, true, sRes); //---------------------------------------------------------- + return true; } /** * Handles a modify reservation request<br> * (NOTE: <b>NOT SUPPORTED YET</b>). * @param message the advance reservation message received. + * @return <tt>false</tt>. */ - public void handleModifyReservation(ARMessage message) { + public boolean handleModifyReservation(ARMessage message) { System.out.println(super.get_name() + ".handleModifyReservation(): not supported at the moment."); + return false; } /** Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARTPolicy.java 2008-05-08 07:44:14 UTC (rev 172) @@ -30,32 +30,40 @@ * A method that handles a new advanced reservation request. * @param message the advance reservation message received requesting * the reservation + * @return <tt>true</tt> if the reservation was accepted; + * <tt>false</tt> otherwise. * @pre message != null */ - void handleCreateReservation(ARMessage message); + boolean handleCreateReservation(ARMessage message); /** * A method that handles a modify reservation request. * @param message the advance reservation message received requesting - * the change + * the change + * @return <tt>true</tt> if the reservation was modified; + * <tt>false</tt> otherwise. * @pre message != null */ - void handleModifyReservation(ARMessage message); + boolean handleModifyReservation(ARMessage message); /** * A method that handles a cancel reservation request. * @param message the advance reservation message received requesting * the cancellation + * @return <tt>true</tt> if the reservation was cancelled; + * <tt>false</tt> otherwise. * @pre message != null */ - void handleCancelReservation(ARMessage message); + boolean handleCancelReservation(ARMessage message); /** * A method that handles a commit reservation request. * @param message the advance reservation message received + * @return <tt>true</tt> if the reservation was committed; + * <tt>false</tt> otherwise. * @pre message != null */ - void handleCommitReservation(ARMessage message); + boolean handleCommitReservation(ARMessage message); /** * A method that handles a query reservation request. Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-05-08 07:44:14 UTC (rev 172) @@ -94,31 +94,23 @@ * or not, <tt>false</tt> otherwise. */ public void gridletSubmit(Gridlet gridlet, boolean ack) { - int reqPE = gridlet.getNumPE(); - - try{ - // reject the Gridlet if it requires more PEs than the resource - // is able to provide - if(reqPE > super.totalPE_){ - String userName = GridSim.getEntityName( gridlet.getUserID() ); - System.out.println(super.get_name() + ".gridletSubmit(): " + - " Gridlet #" + gridlet.getGridletID() + " from " + - userName + " user requires " + gridlet.getNumPE() + " PEs."); - System.out.println("--> The resource has only " + - super.totalPE_ + " PEs."); + // Create a server side Gridlet + SSGridlet sgl = new SSGridlet(gridlet); + boolean success = super.validateGridlet(sgl); + if(!success) { + try { + // reject the Gridlet gridlet.setGridletStatus(Gridlet.FAILED); super.sendFinishGridlet(gridlet); return; } + catch(Exception ex) { + System.out.println(super.get_name() + + ": Exception on submission of a Gridlet"); + return; + } } - catch(Exception ex){ - System.out.println(super.get_name() + - ": Exception on submission of a Gridlet"); - } - // Create a resource Gridlet - SSGridlet sgl = new SSGridlet(gridlet); - //-------------- FOR DEBUGGING PURPOSES ONLY -------------- GridSim.notifyListeners(this.get_id(), @@ -126,29 +118,8 @@ //---------------------------------------------------------- - // the id of the queue where the job can be scheduled - int queueId = profile_.getCorrespondingPartitionID(sgl); - - // if no queue can handle the gridlet, then reject it - if(queueId == UNKNOWN) { - String userName = GridSim.getEntityName( gridlet.getUserID() ); - System.out.println(super.get_name() + ".gridletSubmit(): " + - " Gridlet #" + gridlet.getGridletID() + " from " + - userName + " cannot be handled by any queue in this resource."); - try { - gridlet.setGridletStatus(Gridlet.FAILED); - } catch (Exception ex) { - System.out.println(super.get_name() + - ": Exception on submission of a Gridlet"); - } - super.sendFinishGridlet(gridlet); - return; - } - - sgl.setPartitionID(queueId); - // try to schedule gridlet immediately - boolean success = startGridlet(sgl); + success = startGridlet(sgl); if(!success) { scheduleGridlet(sgl); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-05-08 07:44:14 UTC (rev 172) @@ -100,6 +100,16 @@ // partitions is allowed or not protected boolean allowBorrowing_; + // indicates whether a gridlet should be returned to the user immediately + // if it could not be scheduled to its corresponding partition and the + // borrowing of resources from other partitions is disabled. That is, if + // a gridlet arrives to the resource, the partition does not have enough + // resources, borrowing is disabled and this attribute is true, the gridlet + // will be returned to the user entity. A user may want to change this + // behaviour if he wants to implement manual borrowing or resizing + // of the resource partitions + protected boolean returnGridlet_; + // the number of partitions or queues in this scheduler protected int numPartitions_; @@ -154,6 +164,7 @@ prioritySelector_ = null; lastScheduleUpdate_ = 0.0D; allowBorrowing_ = true; + returnGridlet_ = true; ratingPE_ = 0; } @@ -219,6 +230,28 @@ } /** + * This method is called to specify the behaviour of the policy if a gridlet + * cannot be scheduled to its partition due to the lack of enough resources + * and the borrowing is disabled. If a <tt>true</tt> value is passed to this + * method, it indicates that a gridlet should be returned to the user + * immediately if it could not be scheduled to its corresponding partition + * and the borrowing of resources from other partitions is disabled. That is, + * if a gridlet arrives at the resource, the partition does not have enough + * resources, borrowing is disabled and the returnGridlet behaviour is true, + * the gridlet will be returned to the user entity. This prevents the policy + * from queueing gridlets even if it will never be able to serve them. + * A user may want to change this behaviour if he wants to implement manual + * borrowing or resizing of the resource partitions. In such a case, the + * gridlets will be queued even if they cannot be handled by its partition + * at the time of arrival. + * @param returnGridlet <tt>true</tt> indicates that the gridlet should be + * returned; <tt>false</tt> otherwise. + */ + public void setReturnGridletBehaviour(boolean returnGridlet) { + returnGridlet_ = returnGridlet; + } + + /** * Sets the priority selector to be used by this scheduler. The selector * defines what priorities the scheduler should assign to the gridlets. * @param selector the selector to be used. @@ -339,30 +372,23 @@ * or not, <tt>false</tt> otherwise. */ public void gridletSubmit(Gridlet gridlet, boolean ack) { - int reqPE = gridlet.getNumPE(); - - try { - // reject the Gridlet if it requires more PEs than the resource - // is able to provide - if(reqPE > super.totalPE_){ - String userName = GridSim.getEntityName( gridlet.getUserID() ); - System.out.println(super.get_name() + ".gridletSubmit(): " + - " Gridlet #" + gridlet.getGridletID() + " from " + - userName + " user requires " + gridlet.getNumPE() + " PEs."); - System.out.println("--> The resource has only " + - super.totalPE_ + " PEs."); + // Create a server side Gridlet + SSGridlet sgl = new SSGridlet(gridlet); + boolean success = validateGridlet(sgl); + if(!success) { + try { + // reject the Gridlet gridlet.setGridletStatus(Gridlet.FAILED); super.sendFinishGridlet(gridlet); return; } + catch(Exception ex) { + System.out.println(super.get_name() + + ": Exception on submission of a Gridlet"); + return; + } } - catch(Exception ex) { - System.out.println(super.get_name() + - ": Exception on submission of a Gridlet"); - } - // Create a resource Gridlet - SSGridlet sgl = new SSGridlet(gridlet); if(prioritySelector_ != null) sgl.setPriority(prioritySelector_.getSchedulePriority(sgl)); @@ -373,26 +399,6 @@ //---------------------------------------------------------- - // the id of the queue where the job can be scheduled - int queueId = profile_.getCorrespondingPartitionID(sgl); - - // if no queue can handle the gridlet, then reject it - if(queueId == UNKNOWN) { - String userName = GridSim.getEntityName( gridlet.getUserID() ); - System.out.println(super.get_name() + ".gridletSubmit(): " + - " Gridlet #" + gridlet.getGridletID() + " from " + - userName + " cannot be handled by any queue in this resource."); - try { - gridlet.setGridletStatus(Gridlet.FAILED); - } catch (Exception ex) { - System.out.println(super.get_name() + - ": Exception on submission of a Gridlet"); - } - super.sendFinishGridlet(gridlet); - return; - } - - sgl.setPartitionID(queueId); sgl.setStatus(Gridlet.QUEUED); queuedGridlets_.add(sgl); backfillGridlets(GridSim.clock()); @@ -611,6 +617,61 @@ // -------------------- PROTECTED METHODS ---------------------------- /** + * Checks whether the gridlet can be handled by the resource. That is, + * verifies if it does not require more resources than what the resource + * can provide and if the partition can handle the request. + * @param sgl the server side gridlet to be examined + * @return <tt>true</tt> if it can be handled; <tt>false</tt> otherwise. + */ + protected boolean validateGridlet(SSGridlet sgl) { + int reqPE = sgl.getNumPE(); + + // reject the Gridlet if it requires more PEs than the resource + // is able to provide + if(reqPE > super.totalPE_){ + String userName = GridSim.getEntityName(sgl.getSenderID()); + System.out.println(super.get_name() + ".validateGridlet(): " + + " Gridlet #" + sgl.getID() + " from " + + userName + " user requires " + sgl.getNumPE() + " PEs."); + System.out.println("--> The resource has only " + + super.totalPE_ + " PEs."); + return false; + } + + // the id of the queue where the job can be scheduled + int queueId = profile_.getCorrespondingPartitionID(sgl); + + // if no queue can handle the gridlet, then reject it + if(queueId == UNKNOWN) { + String userName = GridSim.getEntityName(sgl.getSenderID()); + System.out.println(super.get_name() + ".validateGridlet(): " + + " Gridlet #" + sgl.getID() + " from " + + userName + " cannot be handled by any partition of this resource."); + return false; + } + // if a partition can serve the gridlet, but it was not given enough + // resources to do so, the borrowing is disabled and the behaviour is + // to return the gridlet in such case, then returns false, forcing + // the gridlet to be returned to the user + else { + QueuePartition partition = profile_.getPartition(queueId); + if(!allowBorrowing_ && returnGridlet_ + && partition.getInitialNumPEs() < reqPE) { + String userName = GridSim.getEntityName(sgl.getSenderID()); + System.out.println(super.get_name() + ".validateGridlet(): " + + " Gridlet #" + sgl.getID() + " from " + + userName + " user requires " + sgl.getNumPE() + " PEs whereas the " + + "partition does not have enough resources and borrowing " + + "is disabled."); + return false; + } + } + + sgl.setPartitionID(queueId); + return true; + } + + /** * Tries to start a gridlet if there are enough processing elements * available at the current simulation time. * @param sgl the gridlet to be started Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-05-08 07:44:14 UTC (rev 172) @@ -261,6 +261,20 @@ } /** + * Gets the idle PEs as a profile entry + * @return the ranges of PEs available at present in all partitions + */ + public MPProfileEntry getIdlePEs() { + MPProfileEntry entry = new MPProfileEntry(GridSim.clock()); + for(QueuePartition queue: queues_.values()) { + PERangeList list = queue.getIdlePERanges() == null ? + null : queue.getIdlePERanges().clone(); + entry.setPERangeList(queue.getPartitionId(), list); + } + return entry; + } + + /** * Checks what PE ranges are available during the given interval. * @param duration the duration of the Gridlet * @return the list of ranges of PEs available Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-05-08 07:44:14 UTC (rev 172) @@ -109,19 +109,22 @@ * @return the string representation */ public String toString() { + if(super.size() == 0) + return "{[]}"; + StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{"); int index = -1; int last = super.size() - 1; - String delim = ","; for(PERange range : this) { index++; stringBuilder.append(range); - delim = index < last ? delim : "}"; - stringBuilder.append(delim); + if(index < last) + stringBuilder.append(","); } + stringBuilder.append("}"); return stringBuilder.toString(); } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java 2008-05-08 07:44:14 UTC (rev 172) @@ -404,6 +404,24 @@ } return result; } + + /** + * Creates a string representation of the reservation for debugging purposes. + * @return a string representation of this reservation. + * @see java.lang.Object#toString() + */ + public String toString(){ + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("Reservation={Reservation ID: " + reservID_); + stringBuilder.append(", User ID: " + userID_); + stringBuilder.append(", Status: " + getStatusString(status_)); + stringBuilder.append(", Sub. Time: " + submissionTime_); + stringBuilder.append(", Start Time: " + startTime_); + stringBuilder.append(", FinishTime: " + (startTime_ + duration_)); + stringBuilder.append(", Duration: " + duration_); + stringBuilder.append(", Num. PEs: " + numPE_ + "}"); + return stringBuilder.toString(); + } //------------------------ PRIVATE METHODS ------------------------ Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2008-05-08 07:44:14 UTC (rev 172) @@ -157,8 +157,8 @@ catch (Exception ex) { System.out.println(super.get_name() + ": Reservation # " + reservation.getID() + " has not been accepted by "+ - "resource # " + resID + " at time = " + GridSim.clock()); - ex.printStackTrace(); + "resource # " + resID + " at time = " + GridSim.clock() + + ", exception=" + ex.getMessage()); reservation = null; } return reservation; @@ -545,10 +545,11 @@ } /** - * Sends a reservation message. + * Sends a reservation message. This message is protected in case + * the user wants to change it to not consider network delay, for example. * @param message the message to be sent */ - private void sendARMessage(ARMessage message) { + protected void sendARMessage(ARMessage message) { // send message to the destination super.send(message.getDestinationID(), GridSimTags.SCHEDULE_NOW, message.getMessageType(), message); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2008-04-28 06:23:28 UTC (rev 171) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2008-05-08 07:44:14 UTC (rev 172) @@ -167,7 +167,8 @@ * @post $none */ protected double forecastExecutionTime(double availableRating, double length){ - double finishTime = (length / availableRating); + double finishTime = (length / availableRating); + finishTime = (long)(finishTime + 1); // This is as a safeguard since the finish time can be extremely // small close to 0.0, such as 4.5474735088646414E-14. Hence causing This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |