From: <mar...@us...> - 2008-06-18 14:16:56
|
Revision: 185 http://gridsim.svn.sourceforge.net/gridsim/?rev=185&view=rev Author: marcos_dias Date: 2008-06-18 07:16:44 -0700 (Wed, 18 Jun 2008) Log Message: ----------- This update includes cancellation features in the advance reservation policy that uses conservative backfilling and multiple partitions Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/Lublin99Workload.java Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-06-17 07:21:14 UTC (rev 184) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-06-18 14:16:44 UTC (rev 185) @@ -500,15 +500,86 @@ } /** - * Handles a cancel reservation request<br> - * (NOTE: <b>NOT SUPPORTED YET</b>). - * @param message the advance reservation message received. - * @return <tt>false</tt>. + * 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 boolean handleCancelReservation(ARMessage message) { - System.out.println(super.get_name() + - ".handleCancelReservation(): not supported at the moment."); - return false; + double currentTime = GridSim.clock(); + + // gets the reservation id of the message + int reservationId = message.getReservationID(); + boolean success = true; + SSReservation sRes = null; + + // creates a response message to be sent to the requester + ARMessage response = message.createResponse(); + + if(!reservTable_.containsKey(reservationId) + && !expiryTable_.containsKey(reservationId)) { + + System.out.println(super.get_name() + ".handleCancelReservation() " + + "Reservation # " + reservationId + " cannot be cancelled " + + "because the allocation policy could not find it."); + success = false; + } + else if (expiryTable_.containsKey(reservationId)) { + System.out.println(super.get_name() + ".handleCancelReservation()" + + " Reservation # " + reservationId + " cannot be cancelled " + + " because it is already in the expiry list."); + success = false; + } + else if( (sRes = reservTable_.get(reservationId)).getActualFinishTime() <= currentTime ) { + System.out.println(super.get_name() + ".handleCancelReservation()" + + " Reservation # " + reservationId + " cannot be cancelled because " + + " it has already finished."); + success = false; + } + + // if it was not possible to cancel the reservation, then return + // an error message back to the requester + if(!success) { + response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); + sendARMessage(response); + return false; + } + + boolean inProgress = sRes.getStatus() == Reservation.STATUS_IN_PROGRESS; + + // remove the reservation from the reservation table + // and put it into the expiry table + reservTable_.remove(reservationId); + expiryTable_.put(reservationId, sRes); + + // remove/update the entries of the profile + removeReservation(sRes); + + // sets the status of the reservation to cancelled + sRes.setStatus(Reservation.STATUS_CANCELLED); + + //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- + + // If a gridlet has been cancelled, then inform the listeners + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sRes); + + //---------------------------------------------------------------------- + + // performs the compression of the schedule + compressSchedule(sRes.getStartTime(), inProgress); + + //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- + + // Inform the listeners about the new schedule + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + + //---------------------------------------------------------------------- + + // send the response message back to the requester + sendARMessage(response); + return true; } /** Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/Lublin99Workload.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/Lublin99Workload.java 2008-06-17 07:21:14 UTC (rev 184) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/Lublin99Workload.java 2008-06-18 14:16:44 UTC (rev 185) @@ -1180,9 +1180,7 @@ System.out.println(super.get_name() + ": Collecting Gridlets ..."); list_ = new ArrayList<Gridlet>(gridletID_ + 1); gridletsReturned_ = 1; // starts at 1, since gridletID_ starts at 1 too - Object data = null; - Gridlet gl = null; Sim_event ev = new Sim_event(); while ( Sim_system.running() ) @@ -1658,7 +1656,6 @@ } return -1; // error, did not converged } - /* * Returns the GCF @@ -1759,7 +1756,7 @@ w = logGamma(q); p = Math.floor(q); if (p == q) - throw new ArithmeticException("lgamma: Overflow"); + throw new ArithmeticException("logGamma: Overflow"); z = q - p; if (z > 0.5) { p += 1.0; @@ -1767,7 +1764,7 @@ } z = q * Math.sin(Math.PI * z); if (z == 0.0) - throw new ArithmeticException("lgamma: Overflow"); + throw new ArithmeticException("logGamma: Overflow"); z = LOGPI - Math.log(z) - w; return z; } @@ -1780,7 +1777,7 @@ } while (x < 2.0) { if (x == 0.0) - throw new ArithmeticException("lgamma: Overflow"); + throw new ArithmeticException("logGamma: Overflow"); z /= x; x += 1.0; } @@ -1794,7 +1791,7 @@ } if (x > 2.556348e305) - throw new ArithmeticException("lgamma: Overflow"); + throw new ArithmeticException("logGamma: Overflow"); q = (x - 0.5) * Math.log(x) - x + 0.91893853320467274178; if (x > 1.0e8) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |